
if exists(select name from sysobjects where name = 'sp_KhuyenMaiCreateEdit')
	drop proc sp_KhuyenMaiCreateEdit
go
/*
	Created by: Phuoc NH
	Created on: 13/05/2013 (dd/mm/yyyy)
	Description: 
	--

	File:$sql-scripts/Proc.sp_KhuyenMaiCreateEdit.sql
*/


-- =============================================
-- Author		: HP
-- Create date	: 2014-04-03
-- =============================================

CREATE PROCEDURE sp_KhuyenMaiCreateEdit
			
	@KhuyenMaiId		INT,
	@TieuDe     		NVARCHAR(500),
	@GiaNiemYet 		NVARCHAR(50)='',
	@GiaKM      		NVARCHAR(50)='',
	@ThoiGian   		VARCHAR(32)=null,
	@Link       		VARCHAR(500)='',
	@ImageSmall 		VARCHAR(128)='',
	@SiteNguon  		VARCHAR(100)='',
	@Provider   		VARCHAR(100)='',
	@Summary    		NVARCHAR(1000)='',
	@ThuTu      		INT,
	@TrangThai  		TINYINT,
	@NguoiTao   		INT,
	@NguoiSua   		INT
	
AS
BEGIN
	
    IF(@KhuyenMaiId=0)
        BEGIN
        	INSERT INTO KhuyenMai
        	(
		[TieuDe],
		[GiaNiemYet],
		[GiaKM],
		[ThoiGian],
		[Link],
		[ImageSmall],
		[SiteNguon],
		[Provider],
		[Summary],
		[ThuTu],
		[TrangThai],
		[NguoiTao],
		[NguoiSua]
        	) 
        	VALUES 
        	(
		@TieuDe,
		@GiaNiemYet,
		@GiaKM,
		@ThoiGian,
		@Link,
		@ImageSmall,
		@SiteNguon,
		@Provider,
		@Summary,
		@ThuTu,
		@TrangThai,
		@NguoiTao,
		@NguoiSua
        	)
        END
     ELSE
        BEGIN
        set dateformat mdy
            UPDATE KhuyenMai     
            SET
		[TieuDe]     = @TieuDe,
		[GiaNiemYet] = @GiaNiemYet,
		[GiaKM]      = @GiaKM,
		[ThoiGian]   = @ThoiGian,
		[Link]       = @Link,
		[ImageSmall] = @ImageSmall,
		[SiteNguon]  = @SiteNguon,
		[Provider]   = @Provider,
		[Summary]    = @Summary,
		[ThuTu]      = @ThuTu,
		[TrangThai]  = @TrangThai,
		[NguoiTao]   = @NguoiTao,
		[NguoiSua]   = @NguoiSua,
		[NgaySua]    = GETDATE()
	WHERE
		    [KhuyenMaiId] = @KhuyenMaiId;
        END
END
GO


